{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c82f685b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz\n",
      "11493376/11490434 [==============================] - 2s 0us/step\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "from tensorflow.keras import datasets, layers, models\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "(train_images, train_labels), (test_images, test_labels) = datasets.mnist.load_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "52380f3a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((60000, 28, 28), (10000, 28, 28), (60000,), (10000,))"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将像素的值标准化至0到1的区间内。\n",
    "train_images, test_images = train_images / 255.0, test_images / 255.0\n",
    "\n",
    "train_images.shape,test_images.shape,train_labels.shape,test_labels.shape\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ffa63dad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABG0AAADqCAYAAAAYlLi0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAA950lEQVR4nO3debzN1f7H8c9KCBFCiaIiNNwiUTRSmpFKuqXZUIpuuZq4aZI03gZ1KwmFVGTIraSb4ReVMTN1Q1IhGUIU398f9Lmf9e3s09777H32d+/zej4ePXov37W/Z9U+3z18rc9aLggCAQAAAAAAQLTslekBAAAAAAAA4I+4aQMAAAAAABBB3LQBAAAAAACIIG7aAAAAAAAARBA3bQAAAAAAACKImzYAAAAAAAARtHcinStVqhTUrFkzTUNBXpYvX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2m2L8j51GWrVq1UL7ubYk6sEHH/SO9evXT7OdChfeBn7fffdN0+gy54477sj0EBIyceLEmMcuueSSQhxJbpszZ47m999/P67HtGzZUnOdOnVSPSTs0bhxY6+9du3aAp/Tvo/Z6cThbTYpQUye/exw7733esfse1DYueeeq/mWW27RHP7MYn8P7LbAX3zxhdfPljP16NFDc7hsavTo0Zr/+te/aj7rrLO8fvYcdpp6WP369WMew//Yay6/bW7ffvttzQsXLtRsS5JRMOHy8Z49e6b0/LbckfKo6AmX/v8uXN66YsUKzeHfGeTvX//6l+ZwKZK93q677rq4zvfss8967Y4dO2qeNm1aXOfYtWuX5nAZclRKoixm2gAAAAAAAEQQN20AAAAAAAAiqMiUR9lpw2+99ZZ3zK4yHS6JsuxU1FNPPTWFo8tNtoQi3WyJh51+blcrF/F3VRk5cmTax4X0CO9qguS1aNFC808//RSzny3VGTRoUFrHhPSxO/7lV57B7lGJ2blzp+ZevXppfvTRR71+tvT24Ycf9o5dfvnlmm1JlP2MIuKXTs2aNUvzEUcc4fV7/vnnNdup35s2bfL62Z0EX3/9dc1jxozx+oXLpSxbXvD111/H7If/6dy5s2ZbOpAfu6viU089leohIU3iLT1GZuy9d95fh8M7D4V3pEX87PevNm3aeMfC5VLxsDs/iYgsWLAgz37Dhw/32kcffXSe/apXr57wGAobM20AAAAAAAAiiJs2AAAAAAAAEcRNGwAAAAAAgAjKqTVtlixZ4rWfeeYZzXb9ku+//z6u84VrHO221Xvtxf0uEb/eM1z7+c4772j+5z//mdKf+8QTT3jtBx54QPPGjRs1X3nllV6/wYMHp3QcQLazdcHFihWL2a9Lly6a7bocyC5nn312poeQk+xaI3YdmzJlynj97Noldj0pEZHp06drHjhwoObx48d7/ey6RHZL8WuvvdbrF2udgHLlynntc845J888bNgwr59d7ybsySefjHkMeatXr16mh5Dz7DqV4XVlmjdvrrlUqVIp/bmvvPKK17711ltTen6kll1vpW7dupoXL17s9bPrSPXv3z/t48ol3bp1K/A57Pe7ESNGxDxWq1YtzW3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AAAAAARlPbyqE8//dRr2y32Pv/8c82rVq1K6vylS5fW3LVrV+/YPffco7lMmTJJnR/5s9uqjRw50jv2r3/9S/MDDzwQ1/m6devmtW+88UbNtWvXTmaIAIA9jjnmGM32NTVchmzblStXTv/AspzdMthO2w5P4QbycuSRR+aZRUQWLlxY2MPJagMHDtT8zDPPaB40aFCBz12rVi2vbb+D2NLTDh06eP3s6y6i7Y033tAcLl8LX5tIP7sEQq9evTTbksOigpk2AAAAAAAAEcRNGwAAAAAAgAjipg0AAAAAAEAEpX1Nm1GjRuXbjsXWDV544YXesWLFimnu3r275vLlyycxQqRK1apVvXbv3r3zzEA8zj33XM0jRozI4EiyX926dTU3adLEOzZlypTCHg4i4u6779Z8/fXXxzz27LPPaqamH0i9GjVqaJ43b14GR5L96tevr/n555/X3LhxY69fz549Na9fv9471rp1a80tWrTQ3KpVK6/fgQceWKCxInpOO+00zYsWLfKOlSpVqrCHU+TZzyI2F0XMtAEAAAAAAIggbtoAAAAAAABEUNrLo/r27ZtvGwDyYrf5sxmJs1O4J02alMGRIEratGmjefjw4d6xCRMmaLblrXY7XRGRMmXKpGdwAFBAJUuW1NypUyfvWLgNiPzxvRCICmbaAAAAAAAARBA3bQAAAAAAACIo7eVRAAAgesqVK6c5vEPbPffco7l///6awzsBspsUAABAejHTBgAAAAAAIIK4aQMAAAAAABBB3LQBAAAAAACIINa0AQCgiLPr24iIPPPMM3lmAAAAFC5m2gAAAAAAAEQQN20AAAAAAAAiyAVBEH9n59aKyIr0DQd5qBEEQeVUnYznMGN4HrMfz2Fu4HnMfjyHuYHnMfvxHOYGnsfsx3OYG2I+jwndtAEAAAAAAEDhoDwKAAAAAAAggrhpAwAAAAAAEEHctAEAAAAAAIignL9p45xb7pyb55yb45ybkenxIHHOuXOcc0ucc1865+7M9HiQPOdcMefcbOfcuEyPBYlzzr3inFvjnJuf6bEgec65bs65+c65Bc65WzM9HiTOOXewc+4/zrlFe57HbpkeExLD62lucM7t45z7zDk3d8+1eF+mx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LNduyxfB0xLVr1yZ87s8//zzPLOJvk3nrrbdqDr8GVKlSJeGfmws2b97stW0ZadhBBx2kuX379ppr167t9Vu6dKlm+7r7zjvveP0qV66s+ayzztJ8++23e/02bdqk+YwzztC8YcOGmGMFskHHjh01h1/7ypcvr9luKSryxy1HE/XCCy947Z49e+bZL7w97YgRI1I2BqTe8uXLNS9evDhmv3POOSeu861bt07z3LlzvWPTpk3TfOmll2quU6dOXOfORTVr1izwOWzZYffu3TUffPDBBT43YnvllVc029dbW/4mIrJjxw7N9913n+YXX3zR63f22WdrHj9+vOZrrrnG61erVi3N8V6X+HMVK1bUbD9DivjfE2x5YriMqkyZMpqPPPLIVA8xrZhpAwAAAAAAEEHctAEAAAAAAIigrCyPsrp27ao5PJ0/1jT78C43dpXv8HQrpF+jRo00h8tg7HNTqlQpzbbsApnTpEkTzXaq6MqVK71+djr2Dz/8oHnkyJFevwEDBmgO775g7dq1S7NdMX7WrFlev4kTJ2rea6+ic486vKOTLSELs6Uc//jHPzTb50nEn9L97rvvag7vWGKn1NsV/JctW+b169y5c57naN68udePHaOQbWzZqM3pMHbsWM33339/zH7FixfX3KlTJ+8YJVGZZ3eIWrVqlXfs//7v/+I6h31NbdCggebZs2d7/davX685/F5tX4u//PJLzXZHnaJg586dmqdMmaI5v88l1gUXXOC17XWK9Jk/f77X/vXXXzXvvXfsr7z2s6MtZ8pvRyG7u234M5dd9oHyqNSxu0dNnz7dO2ZfN9u2bRvzHHaXN8qjAAAAAAAAUGDctAEAAAAAAIggbtoAAAAAAABEUNavaWOde+65cfUL16Taul1bEz5nzhyv34oVKzSzzsKf+/TTTzXXr1/fO1aiRAnN//73vzU//fTTXj/7fNja0nAtY7169Qo2WKTUIYcckm/7d+Fr9rTTTtP87LPPara/S/n5+OOPvfZjjz2muUePHnGdIxd88cUXcfe169hYF110kdeO9RyMHj3aa9vn0G4fe/LJJ8ccg11zx66Dg8Lzl7/8JdNDQBJatWqlOby1qWXfW+06VkjOtm3bNK9Zs8Y7NnPmTM32dfOjjz6K63wLFixIakz2cRs3bozZ77rrrtNst6IWEdl///01H3rooUmNIxe0a9dO89tvv605v2vMircfUiu8Fp+V37b1Rx11lOYHH3ww4Z974403eu2jjz464XMgMSeeeKLXnjdvXlyPu/vuu9MxnELBTBsAAAAAAIAI4qYNAAAAAABABOVUeVS8duzY4bVjbZNpS3hERIoVK5a2MWWr7777TnN4mu0333yj+cknn/SOXXnllZorVqyo2W7xLeI/N5s3b9b8008/JTliRJn9vbDTk88880yv36RJk+I6ny19LEo2bNjgtW1JaOvWrWM+zpaELl++POY57DbrthxKRGTp0qWa//rXv+b5+PA58tuSHIXj8MMPz/QQECc7vTveLYjD1yn+nC1Z6t27t3dszJgxmhcvXpzU+ffbbz/N++67r2a7PbuIv22x1aFDB68da8tv5G316tWaX3nlFe/YW2+9pdmWOh1//PFeP1tWOnDgQM3hkjlkXvXq1WMeK1u2bNrOjcJht3uP930x2zDTBgAAAAAAIIK4aQMAAAAAABBBRbI8qmfPnnH1u/76670209/+yE7BDe9W0K9fP8227CU/Tz31VMxjZ511lmZWZs99e+/9v5en8FTveMujjjjiiJSOKVsls5NFuBzUnsPuThXeGeyXX37RbHcfmTp1qtfPlgYAiC1c0j179mzN9roMX+f//Oc/NdeuXTtNo8tdtpT0gw8+8I7ts88+mi+44ALvmH3ds7t7lSxZ0utXs2ZNzfbzZd26db1+S5Ys0XzYYYdptiWmIn6JFf7cxIkTNcfaRVFE5KGHHtIcLuF/5513NNvyqCOPPDIFI0SiMlUWE/5MWq5cuYyMoygrVaqUZvteePrpp3v9wkufZBNm2gAAAAAAAEQQN20AAAAAAAAiiJs2AAAAAAAAEZTRNW1+/PFHzddee613zG73a7eNTZbdmvrFF1+M6zFt2rQp8M/NdV27dtX8wAMPeMduueWWPHOYXXfEbhcs4td8P/zww5qpFy089tp56aWXvGO29r5t27Yp/bk7d+7UPHfu3LgeE94qtXHjxikdU7Zo2bKl17brS40ePdo7Nm3aNM32//PmzZtjnn/QoEGawzXklSt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kgIs8HQVBfRLaIyJ2ZHRJQdO2Zxt9SRN7M9FiQHOfcviLytojcGgTBpkyPB/FzzlUQkVYicqiIHCQiZZxzV2Z2VEgCn22yXBAEi0TkERGZILtLo+aKyG8ZHVSK5fxNm9/tmeb2sYick9mRIBlBEKze8+81IjJKdtcsIgtxLWa1VSKyysySekt2f9ABkBnnisisIAh+yPRAkLg9a7y9LSKvB0EwMtPjQcLOFJGvgyBYGwTBryIyUkSaZHhMSByfbXJAEAQDgiBoEATBqbK7DDxn1rMRyfGbNs65ys658ntyKdn94ro4o4NCwpxzZfYs0id7piu2kN3T4JAluBZzQxAE34vIN865Onv+qLmIsGgmkDmXC6VRWWnPAv0DRGRREARPZHo8SMpKETnROVd6z/PZXHavTYQswmeb3OCcq7Ln34eISBvJsffGvTM9gDSrKiKD9uyssJeIjAiCYFyGx4TEHSAio3a/H8reIjI0CIL3MjskJIhrMXfcIiKv7ynL+K+IXJvh8SABzrlhInK6iFRyzq0SkXuDIBiQ2VEhGXvq9s8SkU6ZHguS0lRE2ovIvD3rvYmI3B0EwfjMDQmJCILgU+fcWyIyS3aXYswWkRczOyokic822e9t59z+IvKriHQJguCnTA8olXJ6y28AAAAAAIBsldPlUQAAAAAAANmKmzYAAAAAAAARxE0bAAAAAACACOKmDQAAAAAAQARx0wYAAAAAACCCuGkDAAAAAAAQQdy0AQAAAAAAiCBu2gAAAAAAAETQ/wNrQ6R5hPjjKgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 1440x720 with 20 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(20,10))\n",
    "for i in range(20):\n",
    "    plt.subplot(5,10,i+1)\n",
    "    plt.xticks([])\n",
    "    plt.yticks([])\n",
    "    plt.grid(False)\n",
    "    plt.imshow(train_images[i], cmap=plt.cm.binary)\n",
    "    plt.xlabel(train_labels[i])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1561b663",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((60000, 28, 28, 1), (10000, 28, 28, 1), (60000,), (10000,))"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#调整数据到我们需要的格式\n",
    "train_images = train_images.reshape((60000, 28, 28, 1))\n",
    "test_images = test_images.reshape((10000, 28, 28, 1))\n",
    "\n",
    "train_images, test_images = train_images / 255.0, test_images / 255.0\n",
    "\n",
    "train_images.shape,test_images.shape,train_labels.shape,test_labels.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6f360d04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "conv2d (Conv2D)              (None, 26, 26, 32)        320       \n",
      "_________________________________________________________________\n",
      "max_pooling2d (MaxPooling2D) (None, 13, 13, 32)        0         \n",
      "_________________________________________________________________\n",
      "conv2d_1 (Conv2D)            (None, 11, 11, 64)        18496     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_1 (MaxPooling2 (None, 5, 5, 64)          0         \n",
      "_________________________________________________________________\n",
      "flatten (Flatten)            (None, 1600)              0         \n",
      "_________________________________________________________________\n",
      "dense (Dense)                (None, 64)                102464    \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 10)                650       \n",
      "=================================================================\n",
      "Total params: 121,930\n",
      "Trainable params: 121,930\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model = models.Sequential([\n",
    "    layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),#卷积层1，卷积核3*3\n",
    "    layers.MaxPooling2D((2, 2)),                   #池化层1，2*2采样\n",
    "    layers.Conv2D(64, (3, 3), activation='relu'),  #卷积层2，卷积核3*3\n",
    "    layers.MaxPooling2D((2, 2)),                   #池化层2，2*2采样\n",
    "    \n",
    "    layers.Flatten(),                              #Flatten层，连接卷积层与全连接层\n",
    "    layers.Dense(64, activation='relu'),     #全连接层，特征进一步提取\n",
    "    layers.Dense(10)                               #输出层，输出预期结果\n",
    "])\n",
    "# 打印网络结构\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "be570bab",
   "metadata": {},
   "outputs": [],
   "source": [
    "model.compile(optimizer='adam',\n",
    "              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n",
    "              metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f014bd81",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.7280 - accuracy: 0.7592 - val_loss: 0.2674 - val_accuracy: 0.9189\n",
      "Epoch 2/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.2169 - accuracy: 0.9341 - val_loss: 0.1612 - val_accuracy: 0.9522\n",
      "Epoch 3/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.1408 - accuracy: 0.9571 - val_loss: 0.1097 - val_accuracy: 0.9668\n",
      "Epoch 4/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.1099 - accuracy: 0.9660 - val_loss: 0.0886 - val_accuracy: 0.9743\n",
      "Epoch 5/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.0908 - accuracy: 0.9722 - val_loss: 0.0747 - val_accuracy: 0.9775\n",
      "Epoch 6/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.0792 - accuracy: 0.9755 - val_loss: 0.0747 - val_accuracy: 0.9768\n",
      "Epoch 7/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.0714 - accuracy: 0.9778 - val_loss: 0.0620 - val_accuracy: 0.9807\n",
      "Epoch 8/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.0640 - accuracy: 0.9808 - val_loss: 0.0621 - val_accuracy: 0.9800\n",
      "Epoch 9/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.0599 - accuracy: 0.9819 - val_loss: 0.0551 - val_accuracy: 0.9832\n",
      "Epoch 10/10\n",
      "1875/1875 [==============================] - 14s 8ms/step - loss: 0.0554 - accuracy: 0.9824 - val_loss: 0.0646 - val_accuracy: 0.9799\n"
     ]
    }
   ],
   "source": [
    "history = model.fit(train_images, train_labels, epochs=10, \n",
    "                    validation_data=(test_images, test_labels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7ab5ed13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x1f1839380d0>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAOJElEQVR4nO3df4wc9XnH8c8n5rCpSVocfl3AKhBBGoIECScHQZtCUS1AbW2aQnHbyEmpTBKoEilVSigpUKWNRRuStkloLsGyG1FCWkAQiaZBLohGkTAHdWyDAVPqgLFrg6hqEwX7bD/948bkYm6/e96d3dnjeb+k0+7Os7Pz3OIPszffnfk6IgTgze8tTTcAoD8IO5AEYQeSIOxAEoQdSOKwfm7scM+OOZrbz00CqbymH2tP7PZUta7CbvsiSX8raZakb0TE8tLz52iu3u8Lu9kkgIJHYnXLWscf423PkvQVSRdLOl3SEtund/p6AHqrm7/ZF0h6NiKei4g9kr4laVE9bQGoWzdhP0HSC5Meb6mW/Qzby2yP2R4b1+4uNgegG92EfaqDAG/47m1EjEb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40XCdpbfVzSdPvXaGvvrxvfF0WSIJv0AFJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEv8PTjgwm1gkiKQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(test_images[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c1473b7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  4.515862  ,   5.769114  ,  12.306466  ,  -5.415044  ,\n",
       "       -14.143166  ,  -9.336751  ,   0.5946197 , -19.016245  ,\n",
       "        -0.27732837, -19.111135  ], dtype=float32)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pre = model.predict(test_images)\n",
    "pre[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "231d2bd1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
